import React, { useEffect, useState } from "react";
import { _getMySellerInfo } from "./service";
import { Descriptions, Input, Button, message, Space, Typography } from 'antd';
import { Link } from "react-router-dom";
import {LeftOutlined} from '@ant-design/icons';
const { Paragraph } = Typography;
const Home: React.FC = () => {

    const [datasource, setDatasource] = useState<any>();
    const [inviteLink, setInviteLink] = useState<string>();

    useEffect(() => {
        const fetchData = async () => {
            await _getMySellerInfo().then((dataRes) => {
                console.log(dataRes)
                dataRes.data.code === 200 && setDatasource(dataRes.data.data.info)
            })
        }
         fetchData()
    }, [])
    const createInvite = async () => {
        setInviteLink('https://sale.zjny.cc/userPhone?tuiguang_code=' + datasource.tuiguang_code)
    }

    return (
        <>
         <div className="header">
            <a className="goback" onClick={()=>{window.history.back()}} ><LeftOutlined /></a>
            <div className="header-title">
            个人中心
            </div>
        </div>
            {
                !!datasource &&
                <Descriptions title="" bordered  >
                    <Descriptions.Item label="姓名">{datasource.name}</Descriptions.Item>
                    <Descriptions.Item label="销售组">{datasource.group_name}</Descriptions.Item>
                    <Descriptions.Item label="角色">{datasource.is_group_leader===1 ? "组长" : "组员"}</Descriptions.Item>
                    <Descriptions.Item label="手机号">{datasource.phone}</Descriptions.Item>
                </Descriptions>

            }
            <Space size="large">
                <Button type="primary" style={{marginLeft:"10px"}} onClick={() => createInvite()}>生成邀请链接</Button>
                {
                    !!inviteLink &&
                    <div className="ant-input" style={{"width":"240px"}}>
                        <Paragraph style={{ marginBottom: '0px' }} copyable>{inviteLink}</Paragraph>
                    </div>
                }
            </Space>
        </>
    )
}
export default Home;
